import { Exclude } from 'class-transformer';
import { Length, IsString, IsOptional, IsPhoneNumber, ValidateIf, IsDate, IsNumber, IsArray } from 'class-validator';
import { PartialType } from '@nestjs/swagger';

export class CreateUserDto {
  @IsString()
  nickName: string;

  @IsString()
  userName: string;

  @IsString()
  @Exclude()
  password: string;

  @IsOptional()
  @IsString()
  @Length(11, 11, {
    message: '格式错误：请输入11位手机号',
  })
  @IsPhoneNumber('CN', {
    message: '格式错误：请输入国内手机号',
  })
  @ValidateIf((o) => !!o.phonenumber)
  phonenumber?: string;

  @IsString()
  @IsOptional()
  email?: string;

  @IsDate()
  @IsOptional()
  loginDate?: Date | null;

  @IsString()
  @IsOptional()
  enterpriseId?: string | null;
}

export class UpdateUserDto extends PartialType(CreateUserDto) {}

export class UserBindRoleDto {
  @IsArray()
  roleIds: number[];

  @IsNumber()
  userId: number;
}

export class UserBindEnterpriseDto {
  @IsString()
  enterpriseId: string;

  @IsNumber()
  userId: number;
}
